package com.mmall.test;

import java.io.IOException;
import java.net.URL;
import java.util.List;

import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.google.common.io.Resources;

public class RequestMappingSelector {
	
	/**
	 * 在这里 {@link Resources} 比 {@link Files} 更好用。
	 * <p>
	 * 我只需要读取 resources 目录下的文件即可 {@link Resources} 更好用
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		
		URL resource = RequestMappingSelector.class.getClassLoader().getResource("RequestMapping.txt");
		// System.out.println(resource.getPath());
		List<String> lines = Resources.readLines(resource, Charsets.UTF_8);
		if (null != lines && lines.size() > 0) {
			String prefix = "";
			String target = "";
			for (String line : lines) {
				if (line.contains("@RequestMapping")) {
					int start = line.indexOf('"');
					int end = line.lastIndexOf('"');
					target = line.substring(start+1, end);
					if (line.contains("/")) {
						prefix = target;
						System.out.println(target);
					} else {
						System.out.println(prefix + "/" + target);
					}
				}
			}
		}
	}
}
